package gui.panel_new;

import enums.FileFilterEnum;
import gui.filefilter.*;

import javax.swing.*;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Clase abstracta, provee un conjunto de metodos orientados a brindar una funcionalidad basica propia de las
 * clases que precisan abrir o guardar archivos;
 *
 * @author Jose Martin Rozanec;
 */
public abstract class OpenSavePanel extends JPanel {
    protected JButton openButton;
    protected JButton saveButton;
    protected JFileChooser fileChooser;
    protected FileFilterEnum fileFilter;

    /**
     * This method refreshes the functionality and appearence of the open/save buttons.
     */
    public void refreshOpenSaveButtons() {
//        setUILanguage();
        setOpenActionListener();
        setSaveActionListener();
        setOpenButtonEnabled();
        setSaveButtonEnabled();
        setFocusOnComponent();
        setFileFilter();
    }

    /**
     * This method sets a specific action listener to the save button.
     */
    protected abstract void setSaveActionListener();

    /**
     * This method sets the save button in an enabled or disabled state.
     */
    protected abstract void setSaveButtonEnabled();

    /**
     * This method sets a specific action listener to the open button.
     */
    protected abstract void setOpenActionListener();

    /**
     * This method sets the open button in an enabled or disabled state.
     */
    protected abstract void setOpenButtonEnabled();

    /**
     * This method allows to set focus on a specific element of the panel if needed.
     */
    protected abstract void setFocusOnComponent();

    protected void setFileFilter() {
        switch (fileFilter) {
            case XML:
                fileChooser.setFileFilter(new XMLFileFilter());
                break;
            case TST:
                fileChooser.setFileFilter(new TSTFileFilter());
                break;
            case MCF:
                fileChooser.setFileFilter(new MCFFileFilter());
                break;
            case PNG:
                fileChooser.setFileFilter(new PNGFileFilter());
                break;
            case TXT:
                fileChooser.setFileFilter(new TXTFileFilter());
                break;
            case XLS:
                fileChooser.setFileFilter(new XLSFileFilter());
                break;
            case XLSX:
                fileChooser.setFileFilter(new XLSXFileFilter());
                break;
            case DEFAULT:
                break;
        }
    }

//    public void setUILanguage() {
//        ResourceBundle rb;
//        rb = ResourceBundle.getBundle("JFileChooser", Locale.getDefault());
//
//        UIManager.put
//                ("FileChooser.cancelButtonText",
//                        rb.getString("cancelButtonText"));
//        UIManager.put
//                ("FileChooser.openButtonText",
//                        rb.getString("openButtonText"));
//        UIManager.put
//                ("FileChooser.saveButtonText",
//                        rb.getString("saveButtonText"));
//        /*
//              do the same with :
//                            FileChooser.fileNameLabelText
//                            FileChooser.homeFolderToolTipText
//                            FileChooser.newFolderToolTipText
//                            FileChooser.listViewButtonToolTipTextlist
//                            FileChooser.detailsViewButtonToolTipText
//                            FileChooser.saveButtonText=Save
//                            FileChooser.openButtonText=Open
//                            FileChooser.cancelButtonText=Cancel
//                            FileChooser.updateButtonText=Update
//                            FileChooser.helpButtonText=Help
//                            FileChooser.saveButtonToolTipText=Save
//                            FileChooser.openButtonToolTipText=Open
//                            FileChooser.cancelButtonToolTipText=Cancel
//                            FileChooser.updateButtonToolTipText=Update
//                            FileChooser.helpButtonToolTipText=Help
//
//              Almost all Swing widgets can be customize this way. You can
//              examine the Swing sources to get these values or check
//              http://www.gargoylesoftware.com/papers/plafdiff.html for
//              a list of them.
//
//        */
//    }
}
